package com.hs.sfzy.controller;

import com.github.pagehelper.PageInfo;
import com.hs.sfzy.entity.MyNotice;
import com.hs.sfzy.service.MyNoticeService;
import com.hs.sfzy.until.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName MyNoticeController
 * @Description TODO
 * @Author liuzhuo
 * @Date 2025年08月13日 10:39
 * @Version 1.0
 */
@RestController
@RequestMapping("MyNotice")
public class MyNoticeController {
    @Autowired
    private MyNoticeService myNoticeService;
    @PutMapping
    private R insert(@RequestBody MyNotice myNotice) {
        int i = myNoticeService.insert(myNotice);
        if (i > 0) {
            return R.ok("添加成功！");
        }else {
            return R.fail();
                }
    }
    @DeleteMapping("{id}")
    private R delete(@PathVariable("id") Integer id) {
        int i = myNoticeService.deleteById(id);
        if (i > 0) {
            return R.ok("添加成功！");
        }else {
            return R.fail();
        }
    }
    @PutMapping("update")
    private R update(@RequestBody MyNotice myNotice) {
        int i = myNoticeService.updateById(myNotice);
        if (i > 0) {
            return R.ok("添加成功！");
        }else {
            return R.fail();
        }
    }
    @GetMapping("{id}")
    private R get(@PathVariable("id") Integer id) {
        MyNotice myNotice = myNoticeService.selectById(id);
        return R.ok(myNotice);
    }
@GetMapping("/page")
    public R getMyNoticeList(MyNotice myNotice,
                           @RequestParam(required = false, defaultValue = "1") Integer pageNum,
                           @RequestParam(required = false, defaultValue = "10") Integer pageSize) {
        PageInfo<MyNotice> pageInfo = myNoticeService.getMyNoticeList(myNotice, pageNum, pageSize);
        return R.ok(pageInfo);
    }

    @GetMapping("user/{id}")
    private R getUser(@PathVariable("id") Integer id) {
        List<MyNotice> byUserId = myNoticeService.getByUserId(id);
        return R.ok(byUserId);
    }

}
